package com.cai.primeton.service;

import com.cai.primeton.entity.PType;
import com.cai.primeton.repository.CategoryRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * @version 1.0
 * @author：蔡松坡
 * @date：2021/7/6 12 : 07
 * @package：com.cai.primeton.service
 */
@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryRepo categoryRepo;

    @Override
    public List<PType> findAll() {
        List<PType> all = categoryRepo.findAll();
        return all;
    }

    @Override
    public void save(PType pType) {
        categoryRepo.save(pType);
    }

    @Override
    public PType findById(Integer id) {
        Optional<PType> byId = categoryRepo.findById(id);
        return byId.get();
    }

    @Override
    public void deleteById(Integer id) {
        categoryRepo.deleteById(id);
    }

    @Override
    public String findType(String name) {
        String type = categoryRepo.findType(name);
        return type;
    }
}
